
#include "TeacherDbSaver.h"
#include "../../DbElementProvider/DbElementProvider.h"
#include "../../OdbcConnectionSingleton/OdbcConnectionSingleton.h"

//*
//	 *
TeacherDbSaver::TeacherDbSaver(){

	bool ret=OdbcConnectionSingleton::getInstance()->connect(DbElementProvider::getInstance()->getDbName(),DbElementProvider::getInstance()->getUsername(),DbElementProvider::getInstance()->getPassword());
	if(false==ret){
		//throw;
	}
}

//*
//	 *
TeacherDbSaver::TeacherDbSaver(const string * dbName, const string * username, const string * password){

	if((0!=dbName)&&(0!=username)&&(0!=password)){
		bool ret = OdbcConnectionSingleton::getInstance()->connect(dbName,username,password);
		if(!ret){
		}
	}
}

//*
//	 *
TeacherDbSaver::~TeacherDbSaver(){


}

//*
//	 *
bool TeacherDbSaver::saveTeacher(const string * insuranceNumber, const string * name, const string * lastName, const string * aem, const string * fatherID) {


	SQLHANDLE stmtHandle = OdbcConnectionSingleton::getInstance()->getStmtHandle();

	if(NULL!=stmtHandle){

		SQLRETURN rc;

		bool insertionHasSucceed=false;

		string sqlString = "INSERT INTO teachers VALUES ('"
				+ (*insuranceNumber) + 	"','"
				+ (*name) +  			"','"
				+ (*lastName) +			"','"
				+ (*aem) +		 		"','"
				+ (*fatherID) +			"');";

		rc = SQLExecDirect(stmtHandle, (SQLTCHAR *)sqlString.c_str(), SQL_NTS);
		if(rc == SQL_SUCCESS){
			insertionHasSucceed=true;

		}
		SQLFreeHandle(SQL_HANDLE_STMT, stmtHandle);
		return insertionHasSucceed;
	}
	return false;
}

